{include file="header.tpl" title="Ny hendelse" logged_in=$logged_in 
    map_type="incident" incident_post=$post CONFIG=$CONFIG}
{include file="incident_header.tpl"}
<br>
{literal}
<script type="text/javascript">
function places(name) {

	var place =
	{
{/literal}
	{section name=locations loop=$areas}
		'{$areas[locations].area}': new Array({$areas[locations].lon}, {$areas[locations].lat}),
		

	{/section}
		'Dummy': new Array(0,0)
		
{literal}
	}
	center_map(place[name]);
};
</script>
{/literal}


{if $captcha_failed}
    {include file='message.tpl'
        type='warn'
        message='Du må skrive inn teksten i bildet for å vise at du er et menneske.'
    }
{elseif !$logged_in}
	{include file='message.tpl'
		type='warn'
		message='Du er ikke innlogget. Bidragene dine
				vil derfor bli f&oslash;rt p&aring; din IP-adresse.'
	}
{/if}
{if $errors}
    {assign var=errhtml value="<ul>"}
    {foreach item=error from=$errors}
        {assign var=err value=$error_msgs.$error}
        {assign var=errhtml value="$errhtml <li>$err</li>"}
    {/foreach}
    {assign var=errhtml value="$errhtml</ul>"}
    {include file="message.tpl" 
        type="warn"
        message=$errhtml}
{/if}

	
<form method="post" action="incident.php" name="incident">

<fieldset class="incident_field" style="float : left; width : 50%"><legend>Hvor skjedde hendelsen?</legend>
<p><strong>Område</strong> &nbsp;&nbsp;
<select name="area" onchange="places(this.value);">

    <option></option>
    {foreach from=$areas item=area}
        <option value="{$area.area}" 
            {if $area.area == $post.area}selected="selected"{/if}
            >{$area.area}</option>
    {/foreach}
</select>
</p>

<div style="width : 100%; height : 400px;" id="map">
</fieldset>

<fieldset class="incident_field"><legend>Detaljer om hendelsen</legend>
    <div style="float : left; margin-right : 2em;">
        <p>
        <strong>Bilnummer</strong><br />
        <input maxlength="12" name="offender" value="{$post.offender}">
        </p>

        <p>
        <strong>Synd</strong><br />
              
        <select name="offense">
              {html_options values=$offenses output=$offenses selected=$post.offense}
              </select>
        </p>

        <p><strong>Kommentar</strong><br />
        <textarea cols="20" rows="5" name="comment">{$post.comment}</textarea></p>

    </div>
    <div style="float : left;">
        <strong>Dato og tidspunkt</strong>
        <div style="margin-top : 0.2em;" id="calendar-container"></div>
   </div>
</fieldset>

{if !$logged_in }
<fieldset class="incident_field"><legend>Er du ett menneske?</legend>
        <img src="captcha_img.php" alt="" /><br />
        Skriv teksten i bildet: <input type="text" name="captcha" value="" /> 
</fieldset>
{/if}



<div class="submit_field">
    <input id="lon" name="lon" value="{$post.lon}" type="hidden" />
    <input id="lat" name="lat" value="{$post.lat}" type="hidden" />
    <input id="date_time" name="date_time" type="hidden" value="{$post.date_time}" />
    <input value="Send inn hendelsen" type="submit" />
</div>

{* setup the calendar *}
<script type="text/javascript">
dateobj = new Date();
this_year = dateobj.getFullYear();
last_year = this_year - 1;
{if $post.date_time}
init_date = new Date();
init_date.setTime("{$post.date_time}"); 
{/if}

function setDateTime(cal) {ldelim}
    var field = document.getElementById('date_time');
    field.value = cal.date.getTime();
{rdelim}

Calendar.setup({ldelim}
    flat:       "calendar-container",
    //inputField: "date_time",
    showsTime:  true,
    timeFormat: "24",
    ifFormat:   "%Y-%m-%d %H:%M",
    onUpdate: setDateTime,
    weekNumbers : false,
    range : [last_year, this_year]
{if $post.date_time}
    , 
    date : init_date
{/if}
{rdelim});
</script>
{include file="footer.tpl"}
